"""
Copyright (c) 2022 Huawei Technologies Co.,Ltd.

openGauss is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:

          http://license.coscl.org.cn/MulanPSL2

THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
"""
"""
Case Type   : 功能测试
Case Name   : to_timestamp支持正负无穷输入
Create At   : 2023/02/21
Owner       : @kyeleze
Description :
    1.to_timestamp正无穷输入
    2.to_timestamp负无穷输入
Expect      :
    1.成功输出infinity
    2.成功输出-infinity
History     :
"""

import unittest
import os

from testcase.utils.Logger import Logger
from testcase.utils.CommonSH import CommonSH


class TimestampTest(unittest.TestCase):
    def setUp(self):
        self.log = Logger()
        self.log.info(f'----{os.path.basename(__file__)} start----')
        self.primary_sh = CommonSH('PrimaryDbUser')

    def test_to_timstamp(self):
        text = '--step1:to_timestamp正无穷输入 expect:成功输出infinity--'
        self.log.info(text)
        sql_cmd = "select to_timestamp('Infinity'::float);"
        self.log.info(sql_cmd)
        result = self.primary_sh.execut_db_sql(sql_cmd)
        self.log.info(result)
        self.assertIn("infinity", result, '执行失败' + text)

        text = '--step2:to_timestamp负无穷输入 expect:成功输出-infinity--'
        self.log.info(text)
        sql_cmd = "select to_timestamp('-Infinity'::float);"
        self.log.info(sql_cmd)
        result = self.primary_sh.execut_db_sql(sql_cmd)
        self.log.info(result)
        self.assertIn('-infinity', result, '执行失败' + text)

    def tearDown(self):
        self.log.info(f'----{os.path.basename(__file__)} end----')
